﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dijiang.Values
{
    public class DBuiltin : DFunction
    {
        public Func<CmdEnv, DSequence, DValue> builtinFunc;
        public DBuiltin(Func<CmdEnv, DSequence, DValue> builtin) : base()
        {
            builtinFunc = builtin;
        }

        public override DValue Call(CmdEnv env, DSequence args)
        {
            return builtinFunc.Invoke(env, args);
        }

        public override DValue Copy()
        {
            return new DBuiltin(builtinFunc);
        }

        public override bool Equals(DValue? other)
        {
            return other is DBuiltin bo && ReferenceEquals(bo.builtinFunc, builtinFunc);
        }

        public override DValue Eval(CmdEnv env)
        {
            return this;
        }

        public override string ToString()
        {
            return "<BuiltinFuncion>";
        }
    }
}
